#include <arm/v7m.h>
#include <asm/io.h>
#include <linux/compiler.h>

#ifndef CONFIG_CPU_V7M_NUM_IRQ
#define CONFIG_CPU_V7M_NUM_IRQ 112
#endif

typedef void (*isrEntry)(void);

extern void __invalid_entry(void);
extern void __irq_entry(void);
extern void __pendsv_entry(void);
extern void irq_entry(void);
extern void __SysTick_Handler(void);

static const isrEntry __aligned(1024) vector_table[16 + CONFIG_CPU_V7M_NUM_IRQ] = {
    [0] = 0,
    [1] = __invalid_entry,
    [2] = __invalid_entry,
    [3] = __invalid_entry,
    [4] = __invalid_entry,
    [5] = __invalid_entry,
    [6] = __invalid_entry,
    [7] = __invalid_entry,
    [8] = __invalid_entry,
    [9] = __invalid_entry,
    [10] = __invalid_entry,
    [11] = __invalid_entry,
    [12] = __invalid_entry,
    [13] = __invalid_entry,
    [14] = __pendsv_entry,
    [15] = __SysTick_Handler,
    [16 ... 16 + CONFIG_CPU_V7M_NUM_IRQ - 1] = irq_entry,
};

unsigned long setup_vectors_base(void)
{
    __raw_writel((unsigned int)vector_table, BASEADDR_V7M_SCB + V7M_SCB_VTOR);

    return (unsigned long)vector_table;
}
